<?php

	namespace Phptricks\system\library\xml;

	use Phptricks\system\library\PhptricksExceptions\PhptricksExceptions as Exc;
	use Phptricks\system\core\library\library;
	use Phptricks\system\library\loaders\loader as loaders;

	/**
	  $xml = xml::getinstance();
	  $xml->load_file("http://www.mstaml.com/section/rss.php");
	  $pharse = $xml->get_child('channel')->item;
	  foreach ($pharse as $key => $value) {
	  echo $value->title . "<br>\n";
	  }
	  exit();
	 */
	class xml implements library{

		private static $_instance = null;
		private $_current_data;
		public $channel;

		public function __construct(){
			
		}

		public static function getinstance(){
			if (self::$_instance === null) {
				self::$_instance = new \Phptricks\system\library\xml\xml();
			}
			return self::$_instance;
		}

		public function load_file($file){
			try {
				$xml = simplexml_load_file($file);
				$this->_current_data = &$xml;
				$this->channel = &$xml;
			} catch (\Exception $exc) {
				throw new Exc($exc->getTraceAsString());
			}
			return true;
		}

		public function get_child($array_child){
			if (!empty($array_child)) {
				return $this->_current_data->{$array_child};
			} else {
				return false;
			}
		}

	}
	